<template>
  
  <a-tree-select
    showSearch
    allowClear
    :disabled="type=='new'?false:true"
    style="width: 100%"
    :dropdownStyle="{ maxHeight: '400px', overflow: 'auto' }"
    :treeData="gData"
    treeNodeFilterProp="title"
    placeholder="请选择"
    treeDefaultExpandAll
    @change="onChange"
    :value="value"
  >
    <!-- <span style="color: #08c" slot="title" slot-scope="{key, value}" v-if="key='0-0-1'">
      Child Node1 {{value}}
    </span> -->
  </a-tree-select>
</template>

<script>
  const gData = [];
  export default {
    props: ['currentValue','type'],
    data() {
      return {
        value: undefined,
        gData,
      };
    },
    methods: {
      getTree() { //获取组织架构树
        this.$post(this.$api.postProviderOrganizationQueryList).then(response => {
          if (response.data.succeed) {
            this.gData = []
            if (response.data.data.length > 0) {
              response.data.data.forEach(el=>{
                this.getData(el)
                if (el.title) {
                  this.gData.push(el)
                }
              })
            }
          }
        })
      },
      getData(data) { //处理树数据
        data.title = data.label
        data.value = data.id
        data.key = data.id //
        data.scopedSlots = { title: 'title', key: 'key', parentId: 'parentId' }
        if (data.children && data.children.length > 0) {
          for(var i = 0; i < data.children.length; i++) {
            this.getData(data.children[i])
          }
        }
      },
      onChange (value) {
        this.value = value
        // this.currentValue = value
      },
    },
    mounted() {
      this.getTree()
    },
    watch: {
      value(value) {
        // this.currentValue = value
        this.$emit('input',value)
      },
      currentValue(value) {
        this.value = this.currentValue
      }
    },
  };
</script>
